package com.example.controller;

import com.alibaba.excel.EasyExcel;
import com.example.easyExcelListener.RegionListener;
import com.example.entity.Region;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @Author ZHAO Yudong
 * @Date 2020/10/27 16:34
 * @description：区域读写
 */
@RestController
@Api(description = "region上传")
public class RegionController {


    @ApiOperation(value = "上传excel")
    @PostMapping("/upload")
    public String upload(@Param("file") MultipartFile file) throws IOException {
        if (file != null) {
            EasyExcel.read(file.getInputStream(), Region.class, new RegionListener()).sheet().doRead();
            return "success";
        } else {
            return "file 为 null";
        }
    }
}
